package com.tjw.jobs;

import com.tjw.constant.RedisConstant;
import com.tjw.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author tjw
 * @Date 2020/10/10
 */
public class CleanImgJob {

    @Autowired
    private JedisPool jedisPool;

    public void cleanImg(){

        Jedis resource = jedisPool.getResource();

        Set<String> set = resource.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(set.size()>0){
            for (String fileName : set) {
                System.out.println("定时清理垃圾图片:"+fileName);
                //从七牛云服务器删除
                QiniuUtils.deleteFileFromQiniu(fileName);
            }
            resource.del(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        }
        resource.close();
    }

}
